// pages/checkList/checkList.js
import util from '../../utils/util'
Page({

  data: {
    list:[],
    peopleCount:0,
    title:''
  },
  onLoad: function (options) {
    wx.showLoading({
      title: '数据加载中..',
      mask: true,
    });
      
    console.log(options);
    const {id,peopleCount,title} = options;
    this.setData({
      peopleCount,
      title
    })
    const that = this;
    wx.cloud.callFunction({
      name:'downApplicationForm',
      data:{
        id
      },
      success:res=>{
        // console.log('获取报名者的相关信息',res);
        that.setData({
          list:res.result.data.list
        })
        wx.hideLoading();
      },
      fail:err=>{
        // console.log(err);
        wx.hideLoading();
          
      }
    })
  },


  // 导出数据
  exportData(){
    wx.showLoading({
      title: '表格生成中..',
      mask: true,
    });
      
    let {list,title} = this.data;
    console.log('导出数据');
    wx.cloud.callFunction({
      name:'exportExcel',
      data:{
        list,
        cloudPath:util.wxuuid(),
        title
      },
      success:res=>{
        console.log(res);
        // 从云存储里面取出表格
        wx.cloud.downloadFile({
          fileID:res.result.fileID,
          success:res=>{
            // console.log('从云存储中获取数据',res.tempFilePath);
            wx.openDocument({
              filePath:res.tempFilePath,
              fileType: 'xlsx',
              success: (result) => {
                // console.log('打开文档成功');
                wx.hideLoading();
                  
              },
              fail: () => {},
              complete: () => {}
            });
          },
          fail:err=>{
            // console.log(err)
          }
        });
          
      },
      fail:err=>{
        // console.log(err)
      }
    })
  }
})